package com.oceanstar.mapper;

import com.oceanstar.Pojo.HealthInfo;
import com.oceanstar.Pojo.MarkMessage;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface HealthMapper {
    // 插入健康记录
    @Insert("INSERT INTO healthinfo(id, medical_history, allergy_history, heart_rate, blood_pressure, blood_sugar, weight, update_time) VALUES(#{id}, #{medicalHistory}, #{allergyHistory}, #{heartRate}, #{bloodPressure}, #{bloodSugar}, #{weight}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    void insertHealthInfo(HealthInfo healthInfo);

    // 查询健康历史
    @Select("SELECT * FROM healthinfo WHERE id = #{id} ORDER BY update_time DESC")
    List<HealthInfo> selectHealthHistory(@Param("id") Integer id);

    // 插入标记老人
    @Insert("INSERT INTO mark_message (elderly_id, reason, last_update) VALUES (#{elderlyId}, #{reason}, #{lastUpdate})")
    void insertMarkElder(MarkMessage message);

    // 取消标记老人
    @Delete("DELETE FROM mark_message WHERE elderly_id = #{elderlyId}")
    void deleteMarkElder(MarkMessage message);

    // 列表查询标记老人
    @Select("SELECT * FROM mark_message ORDER BY last_update DESC LIMIT #{offset} , #{pageSize}")
    List<MarkMessage> selectMarkedElderList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

    // 统计标记老人总数
    @Select("SELECT COUNT(*) FROM mark_message")
    long countMarkedElderList();
}